package com.xiaoy.core.report.fusionchart.radarChart.util;

import java.util.List;

import com.xiaoy.core.report.fusionchart.api.DataGeneratorAdapt;
import com.xiaoy.core.report.fusionchart.radarChart.entity.Category;
import com.xiaoy.core.report.fusionchart.radarChart.entity.Chart;
import com.xiaoy.core.report.fusionchart.radarChart.entity.DataSet;
import com.xiaoy.core.report.fusionchart.radarChart.entity.Set;

public class JsonDataGenerator extends DataGeneratorAdapt {

	@Override
	public String transformData(Chart chart) {
		
		StringBuffer sb=new StringBuffer();
		/**
		 *  chart */
		sb.append("\t\"<chart ");
		sb.append(formap(chart.getAttrs()));
		sb.append(" >\" +\n \n");
		/**
		 * categories */
		List<Category> categories = chart.getCategorys();
		List<DataSet> dataSets = chart.getDataSets();
		
		if(categories.size()>0){
			sb.append("\t\t\"<categories>\"+\n");
			for(Category category:categories){
				sb.append("\t\t\t\"<category ");
				sb.append(formap(category.getAttrs()));
				sb.append(" />\"+\n");
			}
			sb.append("\t\t\"</categories>\"+\n\n");
		}
		if(dataSets.size()>0){
			for(DataSet dataset:dataSets){
				sb.append("\t\t\"<dataset ");
				sb.append(formap(dataset.getAttrs()));
				sb.append(" >\"+\n");
				for(Set set :dataset.getSets()){
					sb.append("\t\t\t\"<set ");
					sb.append(formap(set.getAttrs()));
					sb.append(" />\"+\n");
				}
				sb.append("\t\t\"</dataset>\"+\n\n");
			}
		}
		return sb.toString();
	}
	
}
